<!-- 基础配置-物料管理 -->
<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="种类编码" prop="subclassCode">
        <el-input v-model="queryParams.subclassCode" placeholder="请输入物料编号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="品类编码" prop="categoryCode">
        <el-input v-model="queryParams.categoryCode" placeholder="请输入物料编号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="物料编码" prop="eipMatCode">
        <el-input v-model="queryParams.eipMatCode" placeholder="请输入物料描述" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['develop:GoodsFee:add']">新增
        </el-button>
      </el-col>
      <!--<el-col :span="1.5">
          <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
              <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                         v-hasPermi="['develop:GoodsFee:remove']">删除</el-button>
          </el-popconfirm>
      </el-col>
      <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini"
                  @click="handleExport" v-hasPermi="['develop:GoodsFee:export']">导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
      :max-height="tableMaxHeight">
      <el-table-column type="selection" fixed="left" width="55" align="center" />
      <!-- <el-table-column label="主键" align="center" :show-overflow-tooltip="true" prop="id" width="80" /> -->
      <el-table-column label="采购方总部编码" align="center" :show-overflow-tooltip="true" width="150"
        prop="purchaserHqCode" />
      <el-table-column label="供应商编码" align="center" :show-overflow-tooltip="true" width="150" prop="supplierCode" />
      <el-table-column label="供应商名称" align="center" :show-overflow-tooltip="true" width="150" prop="supplierName" />
      <el-table-column label="品类编码" align="center" :show-overflow-tooltip="true" width="150" prop="categoryCode" />
      <el-table-column label="种类编码" align="center" :show-overflow-tooltip="true" width="150" prop="subclassCode" />
      <el-table-column label="产成品库存数量" align="center" :show-overflow-tooltip="true" width="100" prop="productAmount" />
      <el-table-column label="计量单位" align="center" :show-overflow-tooltip="true" width="100" prop="productUnit" />
      <el-table-column label="物料编码" align="center" :show-overflow-tooltip="true" width="150" prop="eipMatCode" />
      <el-table-column label="物资描述" align="center" :show-overflow-tooltip="true" width="300" prop="eipMatDes" />
      <el-table-column label="规格型号" align="center" :show-overflow-tooltip="true" width="200" prop="speModels" />
      <el-table-column label="电压等级" align="center" :show-overflow-tooltip="true" width="100" prop="voltageLevel" />
      <el-table-column label="存放地点所在市" align="center" :show-overflow-tooltip="true" width="100" prop="storeCity" />
      <!-- <el-table-column label="入库时间" align="center" :show-overflow-tooltip="true" prop="putStorageTime" /> -->
      <el-table-column label="入库时间" align="center" prop="putStorageTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.putStorageTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="采购订单号" align="center" :show-overflow-tooltip="true" width="150" prop="poNo" />
      <el-table-column label="采购订单行项目ID" align="center" :show-overflow-tooltip="true" width="100" prop="poItemId" />

      <el-table-column label="操作" align="center" width="200" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['develop:GoodsFundBack:edit']">修改</el-button>
          <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)" style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
              v-hasPermi="['develop:GoodsFundBack:remove']">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <MaterialManagementForm ref="form" @ok="getList" />
  </div>
</template>

<script>
  import MaterialManagementForm from '@/views/develop/factory/setUp/module/MaterialManagementForm'
  export default {
    name: 'MaterialManagementList',
    components: {
      MaterialManagementForm,
    },
    data() {
      return {
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 研发经费表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          subclassCode: '60004',
          categoryCode: '60',
          eipMatCode: ''
        },
        tableMaxHeight: window.innerHeight - 320,
      }
    },
    created() {
      this.getList();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.form.handleAdd();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        row.putStorageTime = this.parseTime(row.putStorageTime, '{y}-{m}-{d} {h}:{i}:{s}')
        this.$refs.form.handleUpdate(row);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = [row.id] || this.ids;
        for (var i in this.dataList) {
          if (ids.findIndex(item => item == this.dataList[i].id) != -1) {
            ids.splice(ids.findIndex(item => item == this.dataList[i].id), 1)
            this.dataList.splice(i, 1)
            this.$modal.msgSuccess("删除成功");
          }
        }
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 查询物料列表 */
      getList() {
        this.loading = true;
        // getAction(this.url.list, this.queryParams).then(response => {
        //   this.dataList = response.rows;
        //   this.total = response.total;
        //   this.loading = false;
        // });
        setTimeout(() => {
          this.dataList = [
            {
              purchaserHqCode: 'SGCC',
              supplierCode: 'XISE001',
              supplierName: '万合科技',
              categoryCode: '60',
              subclassCode: '60004',
              productAmount: '1823',
              productUnit: '米',
              eipMatCode: 'XZ10011N016BUB250',
              eipMatDes: '4501750V士[PVC聚氧乙烯绝缘]铜-1美_园(蓝色)2.5/2.0',
              speModels: 'ffd',
              voltageLevel: '一级',
              storeCity: '山东',
              putStorageTime: '1730618667',
              poNo: 'S8Z110011N01',
              poItemId: '231'
            },
            {
              purchaserHqCode: 'UPDATE',
              supplierCode: '1SKZH1',
              supplierName: '富通',
              categoryCode: '60',
              subclassCode: '60004',
              productAmount: '1823',
              productUnit: '米',
              eipMatCode: 'XZ10011N016BUB250',
              eipMatDes: '铜紧压园形蛟合导体:630(61/3.73);高压/',
              speModels: '低压线瓏',
              voltageLevel: '二级',
              storeCity: '浙江',
              putStorageTime: '1711618667',
              poNo: 'DAHISHID123',
              poItemId: '2'
            },
            {
              purchaserHqCode: 'YS2Z',
              supplierCode: 'YS2Z121',
              supplierName: '汕头高新区奥星光通信设备有限公司',
              categoryCode: '60',
              subclassCode: 'UXY8A1',
              productAmount: '91',
              productUnit: '米',
              eipMatCode: 'XZ10011N016BUB250',
              eipMatDes: '铜-1美_园(蓝色)2.5',
              speModels: 'ffd',
              voltageLevel: '一级',
              storeCity: '汕头',
              putStorageTime: '1710618167',
              poNo: 'DHKASHDIH1231',
              poItemId: '12'
            },
            {
              purchaserHqCode: 'SUN',
              supplierCode: 'SUO121',
              supplierName: '成都康宁线缆有限公司',
              categoryCode: 'PZ0001',
              subclassCode: 'ZL0001',
              productAmount: '1823',
              productUnit: '吨',
              eipMatCode: 'XZ10011N016BUB250',
              eipMatDes: '4501750V士[PVC聚氧乙烯绝缘]铜-1美_园(蓝色)2.5/2.0',
              speModels: 'ffd',
              voltageLevel: '三级',
              storeCity: '成都',
              putStorageTime: '1730618667',
              poNo: 'S8Z110011N01',
              poItemId: '231'
            },
            {
              purchaserHqCode: 'NNCS',
              supplierCode: 'ZU91',
              supplierName: '中联光通信线缆集团有限公司',
              categoryCode: 'PZ0001',
              subclassCode: 'ZL0001',
              productAmount: '1823',
              productUnit: '米',
              eipMatCode: 'SHDIS190812',
              eipMatDes: '45021750V铜-1美',
              speModels: 'SHDI123',
              voltageLevel: '一级',
              storeCity: '杭州',
              putStorageTime: '1630618667',
              poNo: 'SHDIAZIUD122312',
              poItemId: '123'
            },
            {
              purchaserHqCode: 'CNAE',
              supplierCode: '9011',
              supplierName: '成都成飞线缆有限公司',
              categoryCode: 'PZ0001',
              subclassCode: 'ZL0001',
              productAmount: '1823',
              productUnit: '米',
              eipMatCode: 'XIUXIU1A1',
              eipMatDes: 'PVC聚氧乙烯绝缘',
              speModels: 'T',
              voltageLevel: '四级',
              storeCity: '成都',
              putStorageTime: '1730618667',
              poNo: 'DKASHOD10190H12',
              poItemId: '12'
            },
            {
              purchaserHqCode: 'SGCC',
              supplierCode: '9AK1',
              supplierName: '明达线缆集团有限公司',
              categoryCode: 'PZ0001',
              subclassCode: 'ZL0001',
              productAmount: '1823',
              productUnit: '米',
              eipMatCode: 'XZ10011N016BUB250',
              eipMatDes: '30“50*60',
              speModels: 'ffd',
              voltageLevel: '二级',
              storeCity: '深圳',
              putStorageTime: '1730618667',
              poNo: 'S8Z110011N01',
              poItemId: '39'
            },
            {
              purchaserHqCode: '1OIS',
              supplierCode: 'ZIAE1',
              supplierName: '东风线缆集团股份有限公司 ',
              categoryCode: 'SUO1DD12',
              subclassCode: 'DSIOIO1P212331',
              productAmount: '811',
              productUnit: '米',
              eipMatCode: 'HISUH1ZJKQ',
              eipMatDes: '2.5/2.0',
              speModels: 'Z',
              voltageLevel: '四级',
              storeCity: '新疆',
              putStorageTime: '1730218667',
              poNo: 'SHDID1',
              poItemId: '123'
            },
            {
              purchaserHqCode: 'ISOZ',
              supplierCode: 'OUOA2',
              supplierName: '兰州众邦电线电缆集团有限公司',
              categoryCode: '8110XA1',
              subclassCode: 'SJI1',
              productAmount: '129',
              productUnit: '米',
              eipMatCode: 'CIOIO1',
              eipMatDes: '钢紧压國形绞合导体',
              speModels: 'X',
              voltageLevel: '二级',
              storeCity: '兰州',
              putStorageTime: '1733618667',
              poNo: 'DHKSH0981',
              poItemId: '201'
            },
            {
              purchaserHqCode: 'UIAE',
              supplierCode: 'ksoaiu2',
              supplierName: '天津北达线缆集团有限公司',
              categoryCode: 'ISOA12A1',
              subclassCode: 'DISU123',
              productAmount: '28912',
              productUnit: '吨',
              eipMatCode: 'DJOWI9ZD1',
              eipMatDes: '450/750V主[PVC聚氣乙绝缘]铜-1类',
              speModels: '783783',
              voltageLevel: '一级',
              storeCity: '天津',
              putStorageTime: '1732618667',
              poNo: 'SHI18Z12KKJL12',
              poItemId: '21'
            }
          ];
          this.total = 10;
          this.loading = false;
        }, 1000)
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
    }
  }
</script>
